package com.turing.manage.email.user;
/**
 * @desc   User的M层
 * @author wyh
 * @time   2022-01-07
 */

import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import com.turing.manage.email.dao.Dao;
import com.turing.manage.email.dao.DaoImpl;



public class UserService {
Dao dao=new DaoImpl();
/**
 * @desc  1.将注册页面的数据保存到数据库中
 * @param username
 * @param password
 * @param email
 * @param ucode
 * @throws IOException 
 * @throws SQLException 
 * @throws FileNotFoundException 
 * @throws ClassNotFoundException 
 */
public void save(String username, String password, String email, String ucode) throws ClassNotFoundException, FileNotFoundException, SQLException, IOException {
	
	String  sql="  insert into user(id,username,password,email,ustate,ucode)  values(?,?,?,?,?,?)    "; 
	
	  int [] types=new int [6];
	  types[0]=Types.VARCHAR;
	  types[1]=Types.VARCHAR;
	  types[2]=Types.VARCHAR;
	  types[3]=Types.VARCHAR;
	  types[4]=Types.INTEGER;
	  types[5]=Types.VARCHAR;
	  
	  Object []values=new Object[6];
	  values[0]=UUID.randomUUID().toString();
	  values[ 1]= username;
	  values[ 2]= password;
	  values[ 3]= email;
	  values[ 4]= 1;
	  values[ 5]= ucode;
	  
	  dao.executeUpdate(sql, types, values);
	
}
/**
 * @desc 查询该验证码是否存在
 * @param ucode
 * @return
 * @throws SQLException 
 * @throws ClassNotFoundException 
 */
public Map<String, Object> queryUcode(String ucode) throws ClassNotFoundException, SQLException {
	return dao.executeQueryForMap(" select * from user where ucode=?  ", new int []{Types.VARCHAR}, new Object[]{ucode});
}

/**
 * @desc 更新状态位
 * @param ucode
 * @throws ClassNotFoundException
 * @throws FileNotFoundException
 * @throws SQLException
 * @throws IOException
 */
public void updateStatues(String ucode) throws ClassNotFoundException, FileNotFoundException, SQLException, IOException {
   dao.executeUpdate(" update user set ustate =2 where ucode=?  ", new int []{Types.VARCHAR}, new Object[]{ucode});
}

/**
 * @desc 查询全部
 * @return
 * @throws SQLException 
 * @throws ClassNotFoundException 
 */
public List<Map<String, Object>> queryAll() throws ClassNotFoundException, SQLException {
	return dao.executeQueryForList(" select * from user    ");
}
/**
 * @desc 查询user表中用户的生日
 * @return
 * @throws SQLException 
 * @throws ClassNotFoundException 
 */
public List<Map<String, Object>> queryBirthday() throws ClassNotFoundException, SQLException {
	// TODO Auto-generated method stub
	return dao.executeQueryForList(" select * from user  ");
}

	
	
	
}
